package com.kgcx.organization.service;

import com.github.pagehelper.PageHelper;
import com.kgcx.common.bean.RequestData;
import com.kgcx.common.eum.CommonDataEeum;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.organization.domain.Training;
import com.kgcx.organization.mapper.TrainingMapper;
import com.kgcx.organization.rabbitmq.producer.TrainingProducer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;
/**
 * 驾驶员培训服务
 * @author qinze
 *
 */
@Service
public class TrainingService {

	@Resource
	private TrainingMapper trainingMapper;
	@Resource
	private TrainingProducer trainingProducer;

	 @Transactional(rollbackFor = Exception.class)
	public void insertTraining (Training training) {
		training.setStatus(CommonDataEeum.DATA_STATE_NORMAL.getCode());
		training.setCreateTime(new Timestamp(System.currentTimeMillis()));
		training.setUpdateTime(new Timestamp(System.currentTimeMillis()));
		trainingMapper.insertTraining(training);
		trainingProducer.addTrainingProducer(training);
	}

	public List<Training> selectTraining (RequestData rd) {
		Training training = new Training();
		training.setKid(rd.getLong("kid"));
		return trainingMapper.selectTraining(training);
	}
	/**
     * 给监管平台查询车辆信息保险信息
     * @param rd
     * @return
     */
    public List<Training> queryTrainingWithPage(RequestData rd) {
        PageUtils.page(rd);
        PageHelper.orderBy(rd.getOrderBy());
        List<Training> list =trainingMapper.selectTrainingList(rd);
        for (Training training: list) {
            trainingProducer.addTrainingProducer(training);
        }
        return list;
    }
    /**
     * 查询车辆信息保险信息
     * @param rd
     * @return
     */
    public List<Training> queryWithPage(RequestData rd) {
        PageUtils.page(rd);
        PageHelper.orderBy(rd.getOrderBy());
        List<Training> list =trainingMapper.selectTrainingList(rd);

        return list;
    }

}
